<%@ taglib uri="http://tiles.apache.org/tags-tiles" prefix="tiles"%>
<%@ taglib uri="http://tiles.apache.org/tags-tiles-extras" prefix="tilesx" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://www.springframework.org/tags" prefix="spring" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%@ taglib tagdir="/WEB-INF/tags" prefix="tag"%>
<%@ taglib uri="http://www.springframework.org/security/tags" prefix="security"%>
<%@taglib prefix="joda" uri="http://www.joda.org/joda/time/tags" %>

<script type="text/javascript">
function openSaveChangesDialog()
{
  afterFieldEdit('<spring:message code="field.mpid"/>', 'string', 'supportedParticipant.mpid', 'false', new Array());
  afterFieldEdit('<spring:message code="field.role.code"/>', 'string', 'supportedParticipant.roleCode', 'false', new Array());
  afterFieldEdit('<spring:message code="field.effective.from.date"/>', 'dateTime', 'supportedParticipant.eFD', 'false', new Array());
  afterFieldEdit('<spring:message code="field.industry"/>', 'string', 'supportedParticipant.industry', 'false', new Array());
  setTimeout("checkErrorsForSaveChangesDialog()", 100);
}

function enableSave()
{
  if ($(parseIdForJQuery("supportedParticipant.mpid")).val() != '')
  {
    var saveButton = $("#saveButton");
    saveButton.click(function() {openSaveChangesDialog();});
    saveButton.mouseover(function () {buttonHover(this);});
    saveButton.mouseout(function() {buttonNormal(this);});
    saveButton.addClass("button_input").removeClass("button_inputDisabled");
  }

  if ($(parseIdForJQuery("supportedParticipant.eFD")).val() != '')
  {
    var saveButton = $("#saveButton");
    saveButton.click(function() {openSaveChangesDialog();});
    saveButton.mouseover(function () {buttonHover(this);});
    saveButton.mouseout(function() {buttonNormal(this);});
    saveButton.addClass("button_input").removeClass("button_inputDisabled");
  }
}

function updateChange()
{
	  if (changeCountField != null)
	  {
	    changeCountField.value = parseInt(changeCountField.value) + 1;
	    checkButtons(changeCountField.value);
	  }
}

</script>

<form id="adminForm" name="adminForm" method="post">

  <form:hidden path="adminCommand.adminRequestedAction" id="adminCommand.adminRequestedAction"/>
  <form:hidden path="adminCommand.isNew" id="adminCommand.isNew"/>
  <form:hidden path="adminCommand.supportedParticipant.pk" id="adminCommand.supportedParticipant.pk"/>
  <input type="hidden" id="callStatus" name="callStatus" value=""/>

  <tag:errors name="adminCommand"/>

  <table>
    <jsp:include page="/pages/jsp/tiles/admin/errors.jsp"/>
  </table>

  <table align="center">
    <tr>
      <td>
        <table class="adminEdit" align="center">

          <tr>
            <th align="center" width="200px"><spring:message code="field.mpid"/></th>
            <security:authorize ifAllGranted="ROLE_EDITABLE">
            <spring:bind path="adminCommand.supportedParticipant.mpid">
            <td width="400px">
              <input type="hidden" id="${status.expression}_originalValue" name="${status.expression}_originalValue" value="${status.value}"/>
              <input type="text" id="${status.expression}" name="${status.expression}" value="${status.value}" tabindex="1"
                     class="largeTextField" maxlength="30"
                     onkeyup="fieldEdit('${status.expression}');"
                     onchange="afterFieldEdit('<spring:message code="field.mpid"/>', 'string', '${status.expression}', 'false', new Array());"/>&nbsp;*
              <div id="${status.expression}_errorField" class="errorText" style="visibility:hidden;display:none;"></div>
            </td>
            </spring:bind>
            </security:authorize>
            <security:authorize ifNotGranted="ROLE_EDITABLE">
            <td width="400px">${adminCommand.supportedParticipant.mpid}</td>
            </security:authorize>
          </tr>

          <tr>
            <th align="center" width="200px"><spring:message code="field.long.name"/></th>
            <security:authorize ifAllGranted="ROLE_EDITABLE">
            <spring:bind path="adminCommand.supportedParticipant.longName">
            <td width="400px">
              <input type="hidden" id="${status.expression}_originalValue" name="${status.expression}_originalValue" value="${status.value}"/>
              <input type="text" id="${status.expression}" name="${status.expression}" value="${status.value}" tabindex="1"
                     class="largeTextField" maxlength="50"
                     onkeyup="fieldEdit('${status.expression}');"
                     onchange="afterFieldEdit('<spring:message code="field.long.name"/>', 'string', '${status.expression}', 'true', new Array());"/>&nbsp;
              <div id="${status.expression}_errorField" class="errorText" style="visibility:hidden;display:none;"></div>
            </td>
            </spring:bind>
            </security:authorize>
            <security:authorize ifNotGranted="ROLE_EDITABLE">
            <td width="400px">${adminCommand.supportedParticipant.longName}</td>
            </security:authorize>
          </tr>

          <tr>
            <th align="center" width="200px"><spring:message code="field.role.code"/></th>
            <security:authorize ifAllGranted="ROLE_EDITABLE">
            <spring:bind path="adminCommand.supportedParticipant.roleCode">
            <td>
              <input type="hidden" id="${status.expression}_originalValue" name="${status.expression}_originalValue" value="${status.value}"/>
              <select id="${status.expression}" name="${status.expression}" class="smallComboField"
                      onchange="fieldEdit('${status.expression}');afterFieldEdit('<spring:message code="field.role.code"/>', 'string', '${status.expression}', 'false', new Array());">
                <c:forEach items="${roles}" var="item">
                  <option value="${item.value}" <c:if test="${item.value == status.value}">selected</c:if>>${item.name}</option>
                </c:forEach>
              </select>&nbsp;*
              <div id="${status.expression}_errorField" class="errorText" style="visibility:hidden;display:none;"></div>
            </td>
            </spring:bind>
            </security:authorize>
            <security:authorize ifNotGranted="ROLE_EDITABLE">
            <td width="400px">${adminCommand.supportedParticipant.roleCode}</td>
            </security:authorize>
          </tr>

          <tr>
            <th align="center" width="200px"><spring:message code="field.effective.from.date"/></th>
            <security:authorize ifAllGranted="ROLE_EDITABLE">
            <spring:bind path="adminCommand.supportedParticipant.eFD">
            <td width="400px">
                     <script type="text/javascript">$(function(){$.fx.speeds._default=10;$(parseIdForJQuery('${status.expression}')).datepicker({showOn:'button',buttonImage:'pages/images/themed/calendar.png',buttonText:'Select a date',buttonImageOnly:true,showAnim:'fadeIn',duration:'fast',dateFormat:'dd/mm/yy'});});</script>
		      		<input type="hidden" id="${status.expression}_originalValue" name="${status.expression}_originalValue" value="${status.value}"/>
		      		<input type="text" id="${status.expression}" name="${status.expression}" value="${status.value}" maxlength="10" class="dateTextField" tabindex="${tabindex}" onkeyup="fieldEdit('${status.expression}');checkMandatoryItems();"
		      		onchange="zeroTabDatePopulation('${status.expression}');afterFieldEdit('<spring:message code="field.effective.from.date"/>', 'date', '${status.expression}', 'false', new Array());"/><c:if test="${allowNull == 'false'}">&nbsp;*</c:if>
              <div id="${status.expression}_errorField" class="errorText" style="visibility:hidden;display:none;"></div>
            </td>
            </spring:bind>
            </security:authorize>
            <security:authorize ifNotGranted="ROLE_EDITABLE">
            <td width="400px"><joda:format value="${adminCommand.supportedParticipant.EFD}" style="F-" pattern="dd/MM/yyyy"/></td>
            </security:authorize>
          </tr>

          <tr>
            <th align="center" width="200px"><spring:message code="field.effective.to.date"/></th>
            <security:authorize ifAllGranted="ROLE_EDITABLE">
            <spring:bind path="adminCommand.supportedParticipant.eTD">
            <td width="400px">
                     <script type="text/javascript">$(function(){$.fx.speeds._default=10;$(parseIdForJQuery('${status.expression}')).datepicker({showOn:'button',buttonImage:'pages/images/themed/calendar.png',buttonText:'Select a date',buttonImageOnly:true,showAnim:'fadeIn',duration:'fast',dateFormat:'dd/mm/yy'});});</script>
		      		<input type="hidden" id="${status.expression}_originalValue" name="${status.expression}_originalValue" value="${status.value}"/>
		      		<input type="text" id="${status.expression}" name="${status.expression}" value="${status.value}" maxlength="10" class="dateTextField" tabindex="${tabindex}" onkeyup="fieldEdit('${status.expression}');checkMandatoryItems();"
		      		onchange="zeroTabDatePopulation('${status.expression}');afterFieldEdit('<spring:message code="field.effective.from.date"/>', 'date', '${status.expression}', 'false', new Array());"/><c:if test="${allowNull == 'false'}">&nbsp;*</c:if>
              <div id="${status.expression}_errorField" class="errorText" style="visibility:hidden;display:none;"></div>
            </td>
            </spring:bind>
            </security:authorize>
            <security:authorize ifNotGranted="ROLE_EDITABLE">
            <td width="400px"><joda:format value="${adminCommand.supportedParticipant.ETD}" style="F-" pattern="dd/MM/yyyy"/></td>
            </security:authorize>
          </tr>

          <tr>
            <th align="center" width="200px"><spring:message code="field.industry"/></th>
            <security:authorize ifAllGranted="ROLE_EDITABLE">
            <spring:bind path="adminCommand.supportedParticipant.industry">
            <td>
              <input type="hidden" id="${status.expression}_originalValue" name="${status.expression}_originalValue" value="${status.value}"/>
              <select id="${status.expression}" name="${status.expression}" class="smallComboField"
                      onchange="fieldEdit('${status.expression}');afterFieldEdit('<spring:message code="field.industry"/>', 'string', '${status.expression}', 'false', new Array());">
                <c:forEach items="${industries}" var="item">
                  <option value="${item.value}" <c:if test="${item.value == status.value}">selected</c:if>>${item.name}</option>
                </c:forEach>
              </select>&nbsp;*
              <div id="${status.expression}_errorField" class="errorText" style="visibility:hidden;display:none;"></div>
            </td>
            </spring:bind>
            </security:authorize>
            <security:authorize ifNotGranted="ROLE_EDITABLE">
            <td width="400px">${adminCommand.supportedParticipant.industry}</td>
            </security:authorize>
          </tr>
        </table>
      </td>
    </tr>
    <tr>
      <td>
        <table align="center" style="margin-top:10px;">
          <tr>
            <td style="text-align:center;"><jsp:include page="/pages/jsp/tiles/admin/supportedMapEditButtons.jsp"/></td>
          </tr>
        </table>
      </td>
    </tr>
    <jsp:include page="/pages/jsp/tiles/admin/hoverConfirmation.jsp"/>
  </table>
</form>